#ifndef _SHADOW_SOCKET_H_
#define _SHADOW_SOCKET_H_

#include <time.h>

#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>
#include <string>

#define DEFAULT_LISTEN_BACKLOG 10
#define DEFAULT_RECV_BUFFER_SIZE 8192

using std::string;

class SSocket {
	public:
		SSocket();
		~SSocket();
		
		int set_fd(int fd);
		int set_connected_time(time_t t);
		int close();
		int send_all(const char * buf, const int len, int timeout_in_sec);
		int recv_all(string & buf, const int len, int timeout_in_sec);
		int recv_any(string & buf, int timeout_in_sec);
		int connect(const char * ip, int port, int timeout_in_sec);
		int listen(int port);
		int accept(SSocket & new_socket);
		int get_fd();

		time_t get_connected_time();
		time_t get_last_data_input_time();
		time_t get_last_data_output_time();

		bool is_connected();

		int is_writetable(bool & is_writable, int timeout_in_sec);

		time_t get_last_recv_fail_time();
		time_t get_last_send_fail_time();

		int get_index();
		int set_index(int index);

		int get_sock_opt_error(int & s_error);

	protected:
		int set_last_data_input_time(time_t t);	
		int set_last_data_output_time(time_t t);

		int set_flag(int flag);
		int set_to_nonblock(int & old_flag);
		
	private:
		int _fd;
		time_t _last_data_input_time;
		time_t _last_data_output_time;
		time_t _connected_time;
		bool _is_connected;
		int _index;
		time_t _last_recv_fail_time;
		time_t _last_send_fail_time;
		log4cxx::LoggerPtr _logger;
};
#endif 
